#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+5,M=3e7;
vector<pair<int,int> > e[N];
int cnt,f[N],d[N],siz[N],son[N],id[N],top[N],rk[N];
ll qz[N];
void dfs1(int u,int fa,int dep){
	f[u]=fa,d[u]=dep,siz[u]=1;
	int maxn=-1;
	for(auto it:e[u]){
		int v=it.first,w=it.second;
		if(v==fa) continue;
		qz[v]=qz[u]+w;dfs1(v,u,dep+1);siz[u]+=siz[v];
		if(siz[v]>maxn) maxn=siz[v],son[u]=v;
	}
}
void dfs2(int u,int t){
	top[u]=t,id[u]=++cnt,rk[cnt]=u;
	if(son[u]) dfs2(son[u],t);
	for(auto v:e[u])
		if(!id[v.first]) dfs2(v.first,v.first);
}
inline int LCA(int x,int y){
	while(top[x]!=top[y]){
		if(d[top[x]]<d[top[y]]) swap(x,y);
		x=f[top[x]];
	}
	if(d[x]>d[y]) swap(x,y);
	return x;
}
#define ls (x<<1)
#define rs (x<<1|1)
struct tree{
	int l,r,lca;
}c[N<<2];
void build(int x,int l,int r){
	c[x].l=l,c[x].r=r;
	if(l==r) return void(c[x].lca=l);
	int mid=(l+r)>>1;
	build(ls,l,mid),build(rs,mid+1,r);
	c[x].lca=LCA(c[ls].lca,c[rs].lca);
}
int qry(int x,int l,int r){
	if(c[x].l>=l&&c[x].r<=r) return c[x].lca;
	int lca=-1,mid=(c[x].l+c[x].r)>>1;
	if(l<=mid) lca=(lca==-1?qry(ls,l,r):LCA(lca,qry(ls,l,r)));
	if(r>mid) lca=(lca==-1?qry(rs,l,r):LCA(lca,qry(rs,l,r)));
	return lca;
}
int rt[N],tot;
struct treee{
	int lson,rson,sum;
}cc[M];
int bud(int L,int R){
	int p=++tot;cc[p].sum=0;
	if(L==R) return p;
	int mid=(L+R)>>1;
	cc[p].lson=bud(L,mid),cc[p].rson=bud(mid+1,R);
	return p;
}
int ID;
int upd(int x,int L,int R){
	int mid=(L+R)>>1,p=++tot;
	cc[p]=cc[x];
	if(L==R){
		cc[p].sum=1;
		return p;
	}
	ID<=mid?cc[p].lson=upd(cc[x].lson,L,mid):cc[p].rson=upd(cc[x].rson,mid+1,R);
	cc[p].sum=cc[cc[p].lson].sum+cc[cc[p].rson].sum;
	return p;
}
int lo,ro;
bool query(int p,int q,int L,int R){
	if(lo<=L&R<=ro) return cc[p].sum>cc[q].sum;
	int mid=(L+R)>>1;
	if(lo<=mid){
		if(query(cc[p].lson,cc[q].lson,L,mid)) return true;
	}
	if(ro>mid){
		if(query(cc[p].rson,cc[q].rson,mid+1,R)) return true;
	}
	return false;
}
int n,q;
ll lastans;
inline ll work(int p,int l,int r){
	if(l<=p&&p<=r) return lastans=0;
	int lca=qry(1,l,r),TLH=LCA(p,lca);
	if(TLH==lca){
		lo=l,ro=r;
		if(query(rt[id[p]+siz[p]-1],rt[id[p]-1],1,n)) return lastans=0;
		int x=p,mid;
		while(!query(rt[id[top[x]]+siz[top[x]]-1],rt[id[top[x]]-1],1,n)) x=f[top[x]];
		int l_=id[top[x]],r_=id[x],res=top[x];
		while(l_<=r_){
			mid=(l_+r_)>>1;
			if(query(rt[id[rk[mid]]+siz[rk[mid]]-1],rt[id[rk[mid]]-1],1,n)) res=rk[mid],l_=mid+1;
			else r_=mid-1;
		}
		return lastans=qz[p]-qz[res];
	}
	return lastans=qz[p]+qz[lca]-(qz[TLH]<<1);
}
namespace Fastio{
	const int L=1<<21;
	inline char gc(){
	    static char buf[L],*l=buf,*r=buf;
	    if(l==r) r=(l=buf)+fread(buf,1,L,stdin);
	    return (l==r)?EOF:*l++;
	}
	char obuf[L],*p=obuf;
	inline void pc(char c){
	    if(p==obuf+L)
	        fwrite(obuf,1,L,stdout),p=obuf;
	    *p++=c;
	}
	inline void flush(){fwrite(obuf,1,p-obuf,stdout);}
	struct Reader{
	    template <typename T>
	    inline Reader& operator>>(T& x){
	        x=0;char c=gc();
	        while(isdigit(c)) x=(x<<3)+(x<<1)+c-'0',c=gc();
	        return *this;
	    }
	    Reader(){}
	}cin;
	struct Writer {
	    template <typename T>
	    inline Writer& operator<<(T x){
	        static short tp=0,s[40];
	        do s[++tp]=x%10,x/=10;
	        while(x);
	        while(tp) pc(s[tp--]+'0');
	        return *this;
	    }
	    Writer(){}
	    ~Writer(){flush();}
	}cout;
}
#define cin Fastio::cin
#define cout Fastio::cout
signed main() {
	freopen("memory.in","r",stdin);
	freopen("memory.out","w",stdout);
	cin>>n>>q;
	for(int i=1,u,v,w;i<n;i++){
		cin>>u>>v>>w;
		e[u].push_back({v,w});
		e[v].push_back({u,w});
	}
	dfs1(1,0,1),dfs2(1,1);build(1,1,n);
	rt[0]=bud(1,n);for(int i=1;i<=n;i++) ID=rk[i],rt[i]=upd(rt[i-1],1,n);
	while(q--){
		ll p,l,r;cin>>p>>l>>r;p^=lastans,l^=lastans,r^=lastans;
		cout<<work(p,l,r);Fastio::pc('\n');
	}
	return 0;
}
